package com.yanggu.payment.controller;

import com.yanggu.payment.entity.OrderInfo;
import com.yanggu.payment.enums.OrderStatus;
import com.yanggu.payment.service.OrderInfoService;
import com.yanggu.payment.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2022/5/6 20:45
 * @description:
 */
@Api(tags = "商品订单管理")
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("订单列表接口")
    @GetMapping("/list")
    public R orderList() {
        List<OrderInfo> data = orderInfoService.listOrderByCreateTimeDesc();
        return R.ok().data("list", data);
    }

    @ApiOperation("根据订单编号查询订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable("orderNo") String orderNo) {
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if(OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setMessage("支付成功"); //支付成功
        }

        return R.ok().setCode(101).setMessage("支付中......");
    }

}
